package com.zhx.threadcoreknowledge.background;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：zhanghaixuan
 * @date ：Created in 2019-10-05 10:32
 * 用途         ： 构造函数中新建线程
 */
public class MultiThreadsError6 {

    private Map<String,String> stringStringMap;

    public MultiThreadsError6() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                stringStringMap = new HashMap<>();
                stringStringMap.put("1","周一");
                stringStringMap.put("2","周二");
                stringStringMap.put("3","周三");
                stringStringMap.put("4","周四");
                stringStringMap.put("5","周五");
                stringStringMap.put("6","周六");
                stringStringMap.put("7","周七");
            }
        }).start();
    }

    public Map<String,String> getStates(){
        return stringStringMap;
    }

    public static void main(String[] args) {
        MultiThreadsError6 threadsError6 = new MultiThreadsError6();
        Map<String, String> stringStringMap = threadsError6.getStates();
        System.out.println(stringStringMap.get("1"));
        stringStringMap.remove("1");
        System.out.println(stringStringMap.get("1"));
    }
}
